const { dialog } = require("electron").remote;
const create = require('ipfs-http-client')
const {globSource } = require('ipfs-http-client')
const ipfs_client = create({ timeout: 5000 })
function clicked() {
    console.log("you click the button")
    dialog.showOpenDialog({ 
        properties: ['openFile','multiSelections','createDirectory'],
        message:"choose the files upload to ipfs" 
    }).then(result => {
        console.log(result.canceled)
        console.log(result.filePaths)
        result.filePaths.map(function (item,index,ary ) { 
            ipfs_client.add(globSource(item, { recursive: true })).then(file=>{
                console.log(file)
            })
            .catch(err=>{
                console.log(file)
            })
        })
      }).catch(err => {
        console.log(err)
      })
}
onload = function () {
    openButton = document.getElementById("openDialog");

    openButton.addEventListener("click", clicked);
}
